Skip to content

Conversation

@danieljvickers
Copy link
Member

@danieljvickers danieljvickers commented Nov 12, 2025

User description

Description

When doing convergence testing for MHD cases, I noticed that we have no smooth cases to demonstrate convergence higher than 1st order. This PR adds two advection cases that are smooth and able to be used for convergence testing. These test include a 1D case for smooth alfven waves which advects a sine wave at a period of T=1. This is from section 6.3.1 of "The ∇·B=0 Constraint in Shock-Capturing Magnetohydrodynamics Codes" by Gábor Tóth (https://www.sciencedirect.com/author/57194241733/gabor-toth). I was able to generate plots that show convergence. I also added a 2D smooth case, which is a 2D smooth magnetic vortex from section 5.2 of "Implicit hybridized discontinuous Galerkin methods for compressible magnetohydrodynamics" by C. Ciucă, P. Fernandez, A. Christophe, N.C. Nguyen. and J. Peraire (https://www.sciencedirect.com/author/56091995200/ngoc-cuong-nguyen). This vortex advects diagonally at a period of T=10.

Notably the 2D case does NOT converge at 5th order because we do not properly enforce the zero divergence criteria of the magnetic field in cases other than 1D. I am adding this case for posterity. If any future PR adds divergence-free magnetism to MHD, a good verification test will be to do convergence testing on the 2D smooth vortex case and show the appropriate convergence.

Type of change

  • Something else

Scope

  • This PR comprises a set of related changes with a common goal

If you cannot check the above box, please split your PR into multiple PRs that each have a common goal.

How Has This Been Tested?

Tested on NVHPC compilers

Test Configuration:

  • What computers and compilers did you use to test this:

Checklist

  • I have added comments for the new code
  • I have added regression tests to the test suite so that people can verify in the future that the feature is behaving as expected
  • I have added example cases in examples/ that demonstrate my new feature performing as expected.
    They run to completion and demonstrate "interesting physics"
  • I ran ./mfc.sh format before committing my code
  • I cannot think of a way to condense this code and reduce any introduced additional line count

If your code changes any code source files (anything in src/simulation)

To make sure the code is performing as expected on GPU devices, I have:

  • Checked that the code compiles using NVHPC compilers
  • Checked that the code compiles using CRAY compilers
  • Ran the code on either V100, A100, or H100 GPUs and ensured the new feature performed as expected (the GPU results match the CPU results)
  • Ran the code on MI200+ GPUs and ensure the new features performed as expected (the GPU results match the CPU results)
  • Ran my code using various numbers of different GPUs (1, 2, and 8, for example) in parallel and made sure that the results scale similarly to what happens if you run without the new code/feature

PR Type

Enhancement, Tests


Description

  • Add 2D smooth magnetic vortex MHD test case for convergence testing

  • Implement hardcoded initial condition (case 252) with smooth vortex physics

  • Create example case configuration with 1024x1024 grid resolution

  • Generate golden test files for regression verification


Diagram Walkthrough

flowchart LR
  A["Hardcoded IC Case 252"] -- "defines smooth vortex" --> B["2D MHD Vortex"]
  B -- "configured by" --> C["case.py Example"]
  C -- "generates" --> D["Golden Test Files"]
  D -- "enables" --> E["Convergence Testing"]
Loading

File Walkthrough

Relevant files
Enhancement
2dHardcodedIC.fpp
Add smooth magnetic vortex hardcoded initial condition     

src/common/include/2dHardcodedIC.fpp

  • Added case 252 for 2D smooth magnetic vortex from Ciuca et al. paper
  • Implemented velocity field with exponential decay term
  • Implemented magnetic field components matching velocity structure
  • Implemented pressure field with exponential decay profile
+16/-0   
case.py
Create 2D smooth magnetic vortex example configuration     

examples/2D_mhd_magnetic_vortex/case.py

  • Created new example case for 2D smooth magnetic vortex
  • Configured 1024x1024 grid on [-5, 5] domain
  • Set MHD parameters with 5th order WENO scheme
  • Configured periodic boundary conditions and output settings
  • Set fluid properties with gamma = 5/3
+78/-0   
Tests
golden-metadata.txt
Add test metadata for smooth vortex case                                 

tests/A48CA601/golden-metadata.txt

  • Generated metadata for test case A48CA601
  • Recorded CMake configuration and compiler information
  • Documented build environment and system specifications
  • Captured test generation timestamp and git commit hash
+154/-0 
golden.txt
Add golden reference output for test case                               

tests/A48CA601/golden.txt

  • Generated golden reference output for regression testing
  • Contains baseline simulation results for convergence verification
+18/-0   

@qodo-merge-pro
Copy link
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Possible Issue

The pressure initialization formula uses mixed literals (some with _wp, some without) and divides by (2*pi)**3; verify consistency of kind promotion and that the expression matches the reference formulation (including factors of 2π and signs) to avoid precision or scaling errors.

! pressure
q_prim_vf(E_idx)%sf(i, j, 0) = 1._wp + (1 - 2._wp*(x_cc(i)**2 + y_cc(j)**2))* exp(1-(x_cc(i)**2 + y_cc(j)**2)) / ((2._wp * pi)**3)
Performance Risk

Default grid size 1024x1024 with dt=1e-4 and 100k steps is very expensive for CI/regression; consider providing a smaller resolution/time configuration or parameterization for automated tests to keep runtime manageable.

"m": 1024,
"n": 1024,
"p": 0,
"dt": 1.e-4,
"t_step_start": 0,
"t_step_stop": 100000,
"t_step_save": 1000,
# Simulation Algorithm Parameters
Divergence Control

Vortex B-field and velocity are initialized, but no divergence-cleaning or correction is applied; since periodic BCs are used in the example, confirm that ∇·B ≈ 0 analytically/discretely to avoid non-convergence attributed to divergence errors.

! magnetic field
q_prim_vf(B_idx%beg)%sf(i, j, 0)     = -y_cc(j) * exp(1-(x_cc(i)**2 + y_cc(j)**2)) / (2.*pi)
q_prim_vf(B_idx%beg + 1)%sf(i, j, 0) =  x_cc(i) * exp(1-(x_cc(i)**2 + y_cc(j)**2)) / (2.*pi)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High-level Suggestion

The 2D magnetic vortex test case is known to fail its convergence test due to existing solver limitations. It should be removed from this PR and introduced later, along with the necessary solver fixes, to avoid adding non-functional code and maintenance overhead. [High-level, importance: 8]

Solution Walkthrough:

Before:

# PR adds a new 2D test case and its implementation
# examples/2D_mhd_magnetic_vortex/case.py
json.dumps(
    {
        "patch_icpp(1)%hcid": 252,
        # ... other parameters
    }
)

! src/common/include/2dHardcodedIC.fpp
...
case (252) ! MHD Smooth Magnetic Vortex
    ! ... calculations for vortex initial conditions
case (270)
...

# tests/A48CA601/
# (new directory with golden files for the failing test)

After:

# The 2D test case and its related files are removed.
# examples/2D_mhd_magnetic_vortex/case.py
# (file is removed)

! src/common/include/2dHardcodedIC.fpp
...
! case (252) is removed
case (270)
...

# tests/A48CA601/
# (directory is removed)

@codecov
Copy link

codecov bot commented Nov 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 46.02%. Comparing base (bfd732c) to head (7a6566e).
⚠️ Report is 10 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1040   +/-   ##
=======================================
  Coverage   46.02%   46.02%           
=======================================
  Files          67       67           
  Lines       13437    13437           
  Branches     1550     1550           
=======================================
  Hits         6185     6185           
  Misses       6362     6362           
  Partials      890      890           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@danieljvickers
Copy link
Member Author

danieljvickers commented Nov 13, 2025

This PR failed tests, but the problem is that those tests are not the ones that I added. The only modifications were additional hard coded patches, new example files, and new golden files. Mostly noting that it is concerning that basically master has failed the test suite. Rerunning to try getting different output.

Failed test tests/5281BD7B: 2D -> Hypoelasticity -> 2 Fluid(s) after 3 attempt(s).
 [Errno 2] No such file or directory: '/storage/scratch1/6/sbryngelson3/mfc-runners/actions-runner-4/_work/MFC/MFC/tests/5281BD7B/silo_hdf5/p0'
 Failed test tests/DA8AF07E: 2D -> Phase Change model 5 -> 2 Fluid(s) after 3 attempt(s).
 Test tests/DA8AF07E: 2D -> Phase Change model 5 -> 2 Fluid(s): Failed to execute MFC.
 Failed test tests/6F296065: 2D -> Phase Change model 5 -> 3 Fluid(s) after 3 attempt(s).
 Test tests/6F296065: 2D -> Phase Change model 5 -> 3 Fluid(s): Failed to execute MFC.
 Failed test tests/CD6C83A2: 3D -> weno_order=7 -> wenoz=T after 3 attempt(s).
 Test tests/CD6C83A2: 3D -> weno_order=7 -> wenoz=T: Failed to execute MFC.

@sbryngelson sbryngelson merged commit 76b6620 into MFlowCode:master Nov 14, 2025
46 of 56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants